package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.BrowseHistoryDao;
import com.theme.passport.entity.theme.BrowseHistoryEntity;
import com.theme.passport.service.theme.BrowseHistoryService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("browseHistoryService")
public class BrowseHistoryServiceImpl extends ServiceImpl<BrowseHistoryDao, BrowseHistoryEntity> implements BrowseHistoryService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userId = (String) params.get("userId");
        String type = (String) params.get("type");
        IPage<BrowseHistoryEntity> page = this.page(
                new Query<BrowseHistoryEntity>().getPage(params),
                new QueryWrapper<BrowseHistoryEntity>()
                        .eq(StringUtils.isNotBlank(userId), "user_id", userId)
                        .eq(StringUtils.isNotBlank(type), "type", type)
                        .orderByDesc("created")
        );
        return new PageUtils(page);
    }

}